<template>
  <div>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" :isDisplayAdd="editable" :isDisplayExport="false" :isDisplayDeleteBatch="false" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="300" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column prop="lineno" label="行号" width="50px" sortable="custom" sort-by="lineno" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column> -->
        <!-- <el-table-column prop="dispprojectid" label="项目" width="250px" sortable="custom" sort-by="projectid" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="resourcechangeid" label="资源变更" width="150px" sortable="custom" sort-by="resourcechangeid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="resourceapplylineid" label="资源申请明细" width="180px" sortable="custom" sort-by="resourceapplylineid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="numold" label="数量(原)" width="80px" sortable="custom" sort-by="numold" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispunittypeold" label="单位类型(原)" width="120px" sortable="custom" sort-by="unittypeold" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="totalmoneyold" label="总金额(原)" width="100px" sortable="custom" sort-by="totalmoneyold" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="applyexplainold" label="申请说明(原)" width="250px" sortable="custom" sort-by="applyexplainold" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="starttimeold" label="开始时间(原)" width="160px" sortable="custom" sort-by="starttimeold" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="endtimeold" label="结束时间(原)" width="160px" sortable="custom" sort-by="endtimeold" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="resourcecodeold" label="资源编码(原)" width="120px" sortable="custom" sort-by="resourcecodeold" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="resourcenameold" label="资源名称(原)" width="200px" sortable="custom" sort-by="resourcenameold" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="unitpriceold" label="单价(原)" width="100px" sortable="custom" sort-by="unitpriceold" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="状态" width="100px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="starttime" label="开始时间(新)" width="160px" sortable="custom" sort-by="starttime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="endtime" label="结束时间(新)" width="160px" sortable="custom" sort-by="endtime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="num" label="数量(新)" width="100px" sortable="custom" sort-by="num" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="totalmoney" label="总金额(新)" width="100px" sortable="custom" sort-by="totalmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="applyexplain" label="申请说明(新)" width="250px" sortable="custom" sort-by="applyexplain" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)" :disabled="!editable">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" @click.native="doDelete(scope.row.id)" :disabled="!editable">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh" :parentId="parentId" :projectid="projectid"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
import { rmbFormat } from '../../../utils/calculation'

export default {
  name: 'pmResourceChangeLine',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      description: '资源变更明细-列表查询',
      urlPrefix: '/pm/resourceChangeLine/',
      url: {
        // queryCodeList: '/pm/resourceChangeLine/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'lineno',
        sord: 'asc'
      },
      isQueryOnCreated: false,
      pageInfo: {
        currentPage: 1, // 当前页面
        pageSize: 7, // 每页记录数
        pageSizes: ['7', '10', '50'],
        totalCount: 0 // 总数
      }
    }
  },
  props: {
    parentId: {
      type: [Number, String],
      default: ''
    },
    editable: {
      type: Boolean,
      default: true
    },
    projectid: {
      type: [Number, String],
      default: ''
    }
  },
  methods: {
    initPage(param) {
      console.log('initpage方法修改时editable：' + this.editable)
      var editable_that = this.editable
      if (param !== undefined) {
        editable_that = param
      }
      if (editable_that) {
        this.rowDbClickActionType = 'edit'
      } else {
        this.rowDbClickActionType = 'view'
      }
    },
    beforeLoadData() {
      if (!this.parentId) {
        return false
      }
      this.queryParam.parentid = this.parentId
      return true
    },
    moneyFormat(row, column, cellValue, index) {
      return rmbFormat(row[column.property])
    }
  },
  mounted() {
    console.log('初始化时editable：' + this.editable)
  }
}
</script>

<style scoped></style>

